new Vue({
    el:'#newsAdd',
    data:{
        title1:'',
        content:'',
        infoFlag:false,
        infoText:''
    },
    methods:{
        NewsAdd()
        {
            if(this.title1==='')
            {
                this.$refs.span_title1.innerHTML="标题不能为空"
                this.$refs.span_title1.style.color="red"
                this.$refs.span_title1.style.fontSize="12px"
                return false
            }
            if(this.content==='')
            {
                this.$refs.span_content.innerHTML="内容不能为空"
                this.$refs.span_content.style.color="red"
                this.$refs.span_content.style.fontSize="12px"
                return false
            }
            if(confirm("确认保存吗？"))
            {
                axios({
                    url:'/api/newsAdd',
                    params:{
                        title1:this.title1,
                        content:this.content
                    }
                }).then(rs=>{
                    console.log(rs.data)
                    if(rs.data.addMsg==="success")
                    {
                        this.infoFlag=true
                        this.infoText="添加成功"
                    }else{
                        this.infoFlag=true
                        this.infoText="添加失败"
                    }
                }).catch(error=>{
                    console.log(error)
                    alert(error)
                })
            }
        },
        checkTitle()
        {
            axios.get('/api/checktitle1',
                {
                    params:{
                        title1:this.title1
                    }
                }).then(rs=>{
                    console.log(this.$refs.span_title1)
                    if(rs.data.isCheck==="yes"||this.title1==='')
                    {
                        this.$refs.add.disabled=true
                        this.$refs.span_title1.innerHTML="标题已存在"
                        this.$refs.span_title1.style.color="red"
                        this.$refs.span_title1.style.fontSize="12px"
                    }else{
                        this.$refs.add.disabled=false
                        this.$refs.span_title1.innerHTML="标题可用"
                        this.$refs.span_title1.style.color="green"
                        this.$refs.span_title1.style.fontSize="12px"
                    }
            })
        },
        closeInfo()
        {
            this.infoFlag=false
            window.location="/api/newsList.html"
        }
    },
})